import MPRequest from '../utils/request'
export const baseUrl = process.env.HOST

// 获取AccessToken的登录接口
export const authApi = async function (data) {
  console.log('authApi requesting...')
  const res = await MPRequest.post('/authorize', data)
  return res
}

// 获取首页信息接口
export const attachUpload = function (data, type) {
  return MPRequest.upload(`${baseUrl}/attachs/upload`, data, type)
}

// 获取AccessToken的登录接口
export const loginApi = async function (data) {
  console.log('loginApi requesting...')
  const res = await MPRequest.post('/oauth2/wechat', data)
  return res
}

// 发送短信验证码
export const sendcodeApi = function (data) {
  const res = MPRequest.post('/sms/code', data)
  return res
}
// 获取首页信息接口
export const homeApi = () => {
  return MPRequest.get(`${baseUrl}/home`)
}

// 获取商品详情接口
export const getShopDataApi = function (data) {
  return MPRequest.get(`${baseUrl}/shop/spu/${data.id}`)
}

// 添加商品进入购物车
export const addShopToCartApi = function (data) {
  return MPRequest.post(`${baseUrl}/shop/cart/add`, data)
}

// 从购物车批量删除商品
export const deleteShopFromCartApi = function (data) {
  return MPRequest.post(`${baseUrl}/shop/cart/delete`, data)
}

// 提交购物车商品结算
export const balanceShopApi = function (data) {
  return MPRequest.post(`${baseUrl}/shop/cart/balance`, data)
}

// 需要结算的商品查询
export const packShopApi = function () {
  return MPRequest.get(`${baseUrl}/shop/cart/pack`)
}

// 购物车列表
export const getShopCartList = function (page) {
  return MPRequest.get(`${baseUrl}/shop/cart?page=${page}`)
}

// 获取用户地址列表接口
export const getAddressList = function () {
  return MPRequest.get(`${baseUrl}/user/address`)
}

// 绑定手机号接口
export const bindMobileApi = function (data) {
  return MPRequest.post(`${baseUrl}/passport/bind-mobile`, data)
}

// 获取支付参数接口
export const orderCreateApi = function (data) {
  return MPRequest.post(`${baseUrl}/course/order/create`, data)
}

// 创建地址接口
export const createAddressApi = function (data) {
  return MPRequest.post(`${baseUrl}/user/address/create`, data)
}

// 更新地址接口
export const updateAddressApi = function (id, data) {
  return MPRequest.post(`${baseUrl}/user/address/update?id=${id}`, data)
}

// 删除地址接口
export const deleteAddressApi = function (id) {
  return MPRequest.post(`${baseUrl}/user/address/delete?id=${id}`)
}

// 创建订单接口
export const createOrderApi = function (data) {
  return MPRequest.post(`${baseUrl}/shop/order/create`, data)
}

// 创建支付接口
export const createTradeOrderApi = function (data) {
  return MPRequest.post(`${baseUrl}/trade/order/create`, data)
}

// 获取分类列表
export const getCatagoryList = function () {
  return MPRequest.get(`${baseUrl}/shop/category`)
}

// 商城栏目tab列表
export const getShopCatagoryTab = function (id) {
  return MPRequest.get(`${baseUrl}/shop/category/list?id=${id}`)
}

// 商城栏目tab下商品列表
export const getShopCategoryList = function (id, page) {
  return MPRequest.get(`${baseUrl}/shop/category/${id}?page=${page}&per-page=100`)
}

// 个人中心
export const getMemberInfo = function () {
  return MPRequest.get(`${baseUrl}/user/home`)
}

// 获取订单列表数据
export const getOrderListAPI = function (page, type) {
  return MPRequest.get(`${baseUrl}/shop/order?page=${page}&type=${type}`)
}

// 获取订单详情数据
export const getOrderAPI = function (id) {
  return MPRequest.get(`${baseUrl}/shop/order/${id}`)
}

// 获取赛事详情
export const getMatch = function (id) {
  return MPRequest.get(`/event/match/${id}`)
}

// 获取赛事列表
export const getMatchList = function (params) {
  return MPRequest.get(`/event/match/index`, params)
}

// 获取赛事列表
export const getEnrollList = function (params) {
  return MPRequest.get(`/enroll`, params)
}

// 检索列表
export const getSearchList = function (params) {
  return MPRequest.get(`/search`, params)
}
